<?php

class Engine {
	private $last_result;
	public $classMap;

    public function __construct() {
		$this->classMap=$this->Config(require_once("/config.php"));
    }

    public function Config($param){
        foreach($param as $key=>$value){
            switch($key){
                case 'db':
                    $ret[$key]=$this->connect($value);
                    break;
                case 'lang':
                    $ret[$key]=require_once("/lang/lang_".$value.".php");
                    break;
                default:
            }
        }
        return $ret;
    }


	public function fetchAll(){
		return $this->last_result->fetchAll();
	}

	public function db(){
		return $this->classMap['db'];
	}

	public function query($query){
		$this->last_result=$this->db()->prepare($query);
		$this->last_result->execute();
		return $this->last_result;
	}

    private function connect($param){
        $DB=new PDO($param['type'].':host='.$param['host'].';dbname='.$param['base'], $param['user'], $param['pass']);
		$stmt=$DB->prepare("SET NAMES ".$param['char']);
		$stmt->execute();
        return $DB;
    }

}